#!/bin/bash

# 日志目录
LOG_DIR="./logs"
mkdir -p $LOG_DIR

# 启动 Celery Worker
echo "Starting Celery Worker..."
celery -A celery_app.celery_app.app worker --loglevel=debug >> $LOG_DIR/celery.log 2>&1 &
CELERY_PID=$!
echo "Celery Worker started with PID: $CELERY_PID"

# 启动 Flask 应用
echo "Starting Flask Application..."
python lyyj_run.py >> $LOG_DIR/flask.log 2>&1 &
FLASK_PID=$!
echo "Flask Application started with PID: $FLASK_PID"

# 启动 短信 应用
echo "Starting Flask Application..."
python sms_demo/warning_send.py >> $LOG_DIR/sms_demo.log 2>&1 &
SMS_DEMO_PID=$!
echo "SMS_DEMO Application started with PID: SMS_DEMO_PID"

# 保存 PID 到文件
echo $CELERY_PID > $LOG_DIR/celery.pid
echo $FLASK_PID > $LOG_DIR/flask.pid
echo $SMS_DEMO_PID > $LOG_DIR/sms_demo.pid

# 提示信息
echo "Services are running in the background."
echo "Celery logs: $LOG_DIR/celery.log"
echo "Flask logs: $LOG_DIR/flask.log"
echo "SMS_DEMO logs: $LOG_DIR/sms_demo.log"